{% extends "base.html" %}
{% load common_filters %}
{% load static %}
{% load crispy_forms_tags %}

{% block title %}
    Teacher Dashboard | {{ block.super }}
{% endblock title %}

{% block stylesheets %}
    {{ block.super }}
    <!-- Custom styles for this template -->
    <link href="{% static "laioffer/css/dashboard.css" %}" rel="stylesheet">
{% endblock stylesheets %}

{% block content %}

    {% if request.user.current_group == "Teacher" %}
        {% include "_teacher_sidebar.html" %}
        {% elif request.user.current_group == "Supervisor" %}
        {% include "_admin_sidebar.html" %}
        {% elif request.user.current_group == "Student" %}
        {% include "_student_sidebar.html" %}
        {% elif request.user.current_group == "Assistant" %}
        {% include "_ta_sidebar.html" %}
    {% endif %}

    <section id="main-content">
        <section class="wrapper">
            {% include "_message.html" %}

            {% for job in resume_ctx.ordered_jobs %}

                <section class="panel">
                    <div class="panel-heading">
                        {{ job.desc }}
                    </div>
                    <div class="panel-body">

                        {% for version in job.versions %}
                            <div class="panel-group">
                                <div class="panel-info">
                                    <a href="{{ version.url }}" class="inlineblockset">
                                        <h4>version #{{ version.id }}: <span
                                                    class="glyphicon glyphicon-download-alt"></span>
                                        </h4>

                                    </a>
                                </div>
                                <!-- show comments -->
                                {% if version.has_comment %}
                                    {% if version.comment_num > 1 %}
                                        <div class="floatleft1">
                                            <a data-toggle="collapse" data-target="#{{ job.desc }}-{{ version.id }}">
                                                More
                                            </a>
                                        </div>
                                    {% endif %}
                                    <!-- show last comment -->
                                    <div class="commentshow2">
                                        {% with last_comment=version.comments.0 %}
                                        {{ last_comment.text }}
                                        <br>
                                        <div class="floatleft1">
                                            <div class="username">{{ last_comment.author_fullname }}</div>
                                            <div class="createdtime">{{ last_comment.time }}</div>
                                        </div>
                                        {% endwith %}
                                        <hr style=" margin-top: 0;">
                                    </div>
                                    {% if version.comment_num > 1 %}
                                        <div class="panel-group">
                                            <div class="collapse commentshow2" id='{{ job.desc }}-{{ version.id }}'>
                                                {% for comment in version.comments %}
                                                    {% if comment.collapsed %}
                                                        {{ comment.text }}
                                                        <br>
                                                        <div class="floatleft1">
                                                            <div class="username">{{ comment.author_fullname }}</div>
                                                            <div class="createdtime">{{ comment.time }}</div>
                                                        </div>
                                                        <hr style=" margin-top: 0;">
                                                    {% endif %}
                                                {% endfor %}
                                            </div>
                                        </div>
                                    {% endif %}
                                {% endif %}
                                <!-- add comment -->

                                {% if version.can_comment %}
                                    <div>
                                        <form method="post">
                                            {% csrf_token %}
                                            {{ form|crispy }}
                                            <input type="hidden" name="last_resume_pk" value="{{ version.pk }}">
                                            <button type="submit">Add</button>

                                        </form>
                                    </div>
                                {% endif %}

                            </div>
                            <hr>
                        {% endfor %} <!-- job.versions -->
                    </div>
                </section>
            {% endfor %} <!-- resume_ctx.ordered_jobs -->

            {% if view.task %}
                <span id='task_status' data-task_status="{{ view.task.status }}"></span>
            {% endif %}

        </section>
    </section>

{% endblock content %}

{% block javascripts %}
    {{ block.super }}
    <script type="text/javascript" src="{% static "laioffer/js/csrf.js" %}"></script>
    <script type="text/javascript" src="{% static "laioffer/js/rest/task.js" %}"></script>
    <script type="text/javascript">
        $.py = {};
        {% if view.task.id %}
        $.py.task_id = {{ view.task.id }};
        {% endif %}
    </script>
    <script type="text/javascript" src="{% static "js/laioffer/task_btn.js" %}"></script>
{% endblock javascripts %}

